﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="pragma" content="no-cache">  <!-- HTTP 1.1 -->
    <meta http-equiv="cache-control" content="no-cache,must-revalidate">  <!-- HTTP 1.0 -->
    <meta name="renderer" content="webkit|ie-comp|ie-stand" /> <!--优先级：极速模式，兼容模式，IE模式-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
    <title>扬州房产测绘业务管理系统</title>
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../libs/jeasyui-181/themes/color.css">
    <link rel="stylesheet" type="text/css" href="../../css/common.css">
    <script type="text/javascript" src="../../libs/jeasyui-181/jquery.min.js"></script>
    <script type="text/javascript" src="../../libs/jeasyui-181/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../libs/thUtil.js"></script>
    <script type="text/javascript">

        var mainGrid = new UserContol();

        $(function () {
            if (UrlParm.hasParm('text')) {
                $('h1').html(UrlParm.parm('text'));
            }
             //获取上传类型
             $("#UPMATERIALTYPE").combobox('loadData', i18n.MaterialTypeItems);
             //获取材料是否必备
             $("#ISMUST").combobox('loadData', i18n.MaterialIsMustItems);
             //查询
             $('#search_Link').html(button.search).linkbutton({ onClick: mygrid.reload });
             //重置按钮
             $('#reset_Link').html(button.reset).click(ajax.reset);

            $('#insert_Link').html(button.insert).linkbutton({ onClick: ajax.insert });
            $('#update_Link').html(button.insert).linkbutton({ onClick: ajax.update });
            $('#delete_Link').html(button.insert).linkbutton({onClick: ajax.delete});
            $('#resort_Link').html(button.resort).linkbutton({ onClick: ajax.resort });
            //重新整理
            $('#resort_Link').html(button.resort).linkbutton({ onClick: ajax.resort });
            mygrid.init();
        });
        var ajax = {
            reset: function () {
                $('#MATERIALNAME').textbox('clear');
                $('#UPMATERIALTYPE').textbox('clear');
                $('#ISMUST').combobox('clear');
                mygrid.reload();
            },
            getList: function (param, success) {
                //材料名称
                if ($('#MATERIALNAME').textbox('getValue') != '') {
                    param.materialName = $('#MATERIALNAME').textbox('getValue');
                }
                //材料类型
                if ($('#UPMATERIALTYPE').combobox('getValue') != '') {
                    param.upMaterialType = $('#UPMATERIALTYPE').combobox('getValue');
                }
                //是否必备材料
                if ($('#ISMUST').combobox('getValue') != '') {
                    param.isMust = $('#ISMUST').combobox('getValue');
                }

                Network.connect(window.api.materialDicSelectPageList, 'POST', param, function (res) {
                    if (res.code == ResponseCode.OK) {
                        success(res.data);
                    }
                });
            },
            getOne: function (param,success) {
                Network.connect(window.api.materialDicSelectOne, 'POST', param, function (res) {
                    if (res.code == ResponseCode.OK) {
                        success(res.data);
                    }
                });
            },
            insert: function () {
                dlg = window.parent.$.hDialog({
                    href: window.router.materialDicForm + '?n=' + Math.random(),
                    title: '新增事项配置',
                    width: 700,
                    height: 450,
                    onLoad: function () {
                        var row = mygrid.selectRow();

                        //获取上传类型数据
                      window.parent.$("#UPMATERIALTYPE").combobox('loadData', i18n.MaterialTypeItems);

                        //获取是否必备数据
                      window.parent.$("#ISMUST").combobox('loadData', i18n.YesAndNOItems);

                      window.parent.$("tr[name='edit']").hide();
                    },
                    submit: function () {
                        var isValid = window.parent.$('#form').form("validate");
                        if (isValid) {
                            var formData = window.parent.$("#form").serializeJson();
                            Network.connect(window.api.materialDicInsert, 'POST', formData, function (res) {
                                if (res.code == ResponseCode.OK) {
                                    Tools.show('添加成功');
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    }
                });
            },
            update: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length == 0) {
                    Tools.alert('请选择需要修改的数据。'); return;
                }
                dlg = window.parent.$.hDialog({
                    href: window.router.materialDicForm + '?n=' + Math.random(),
                    title: '修改事项配置',
                    width: 700,
                    height: 450,
                    onLoad: function () {
                        var param = { AUTOID: rows[0].AUTOID };

                        //获取上传类型数据
                      window.parent.$("#UPMATERIALTYPE").combobox('loadData', i18n.MaterialTypeItems);
                        //获取是否必备数据
                      window.parent.$("#ISMUST").combobox('loadData', i18n.MaterialIsMustItems);

                        ajax.getOne(param, function (data) {
                            console.log(data);
                          window.parent.$('#form').form('load', data);
                          window.parent.$('#UPMATERIALTYPE').combobox("setValue", data.UPMATERIALTYPE);
                          window.parent.$('#ISMUST').combobox("setValue", data.ISMUST);
                        });

                      window.parent.$("tr[name='edit']").hide();
                    },
                    submit: function () {
                        var isValid = window.parent.$('#form').form("validate");
                        if (isValid) {
                            var formData = window.parent.$("#form").serializeJson();
                            Network.connect(window.api.materialDicUpdate, 'POST', formData, function (res) {
                                if (res.code == ResponseCode.OK) {
                                    Tools.show('修改成功');
                                    dlg.dialog('close');
                                    mygrid.reload();
                                }
                            });
                        }
                    }
                });
            },
            delete: function () {
                var rows = $('#mainGrid').datagrid("getSelections");
                if (rows.length == 1) {
                    Tools.confirm('是否确定删除该数据？', function (result) {
                        if (result) {
                            var formData = { AUTOID: rows[0].AUTOID};
                            Network.connect(window.api.materialDicDelete, 'POST', formData, function (res) {
                                if (res.code == ResponseCode.OK) {
                                    Tools.show('删除成功');
                                    mygrid.reload();
                                }
                            });
                        }
                    });
                }
                else {
                    Tools.alert('请选择需要删除的数据。');
                }
            },
            resort: function () {
                Tools.confirm('是否确定重新整理数据？', function (result) {
                    if (result) {
                        Network.connect(window.api.materialDicReSort, 'POST', {}, function (res) {
                            if (res.code == ResponseCode.OK) {
                                Tools.show('重新整理成功');
                                mygrid.reload();
                            }
                        });
                    }
                });
            }
        }

        var mygrid = {
            init: function () {
                mainGrid.dataGrid.id = 'mainGrid';
                mainGrid.dataGrid.idField = 'APPLICATIONID';
                mainGrid.dataGrid.sortName = 'SORT';
                mainGrid.dataGrid.sortOrder = 'asc';
                mainGrid.dataGrid.toolbar = '#toolbar';
                mainGrid.dataGrid.onLoadSuccess = function (data) {
                    if (data.total == 0)
                        setEmptyData($(this));
                };
                mainGrid.dataGrid.loader = function (param, success, error) {
                    $('#mainGrid').datagrid('clearSelections');
                    ajax.getList(param, success);
                };
                mainGrid.dataGrid.columns = [[
                    { field: 'AUTOID', title: '流水号', halign: 'center', align: 'center', width: 100 },
                    { field: 'UPMATERIALTYPE', title: '材料类型', halign: 'center', align: 'center', width: 150 ,
                        formatter: function (value, row, index) {
                            return Tools.json.findTextById(i18n.MaterialTypeItems, value);
                        }
                    },
                    { field: 'MATERIALNAME', title: '材料名称', halign: 'center', align: 'left', width: 400 },
                    { field: 'PAGECONTENT', title: '材料页数', halign: 'center', align: 'center', width: 100 },
                    { field: 'ISMUST', title: '必备材料', halign: 'center', align: 'center', width: 90,
                        formatter: function (value, row, index) {
                            var returnValue = '<span style="color:{0}">{1}</span>';
                            var text = Tools.json.findTextById(i18n.YesAndNOItems, value);
                            if (value == '1') {
                                return returnValue.format('blue', text);
                            }
                            else if (value == '0') {
                                return returnValue.format('red', text);
                            }
                            else {
                                return value;
                            }
                        }
                    },
                    { field: 'REMARK', title: '备注', halign: 'center', align: 'left', width: 600 },
                    { field: 'SORT', title: '排序编号', halign: 'center', align: 'center', width: 90, sortable: true },

                ]];
                mainGrid.InitdataGrid();
            },
            reload: function () {
                $('#mainGrid').datagrid('reload');//$('#mainGrid').datagrid('clearSelections').datagrid('reload');
            },
            selectRow: function () {
                return $('#mainGrid').datagrid('getSelected');
            }
        };

    </script>

</head>
<body>
<div class="container-wrap">
    <div id="toolbar">
        <div class="container-tit">
            <h1></h1>
        </div>
        <div class="sreach fixed">
            <div class="input-box">
                <select class="easyui-combobox" name="UPMATERIALTYPE" id="UPMATERIALTYPE"
                        data-options="  width: 300,
                                            labelWidth: 80,
                                            labelPosition: 'left',
                                            required: true,
                                            label: '材料类型:',
                                            panelHeight: 'auto',
                                            valueField: 'id',
                                            textField: 'text',
                                            editable: false,"></select>
            </div>
            <div class="input-box" style="width: 360px">
                <input type="text" id="MATERIALNAME" name="MATERIALNAME" class="easyui-textbox" data-options="label:'材料名称:',labelWidth: 80,width:350," />
            </div>
            <div class="input-box" style="width: 210px">
                <select class="easyui-combobox" name="ISMUST" id="ISMUST"
                        data-options="  width: 200,
                                            labelWidth: 80,
                                            labelPosition: 'left',
                                            required: true,
                                            label: '必备材料:',
                                            panelHeight: 'auto',
                                            valueField: 'id',
                                            textField: 'text',
                                            editable: false,"></select>
            </div>
            <a id="search_Link" href="#" class="easyui-linkbutton search">查询</a>
            <a id="reset_Link" href="#" class="easyui-linkbutton default">重置</a>
            <div class="bar-btn" style="margin: 9px">
                <a id="insert_Link" href="#" class="easyui-linkbutton insert">新增</a>
                <a id="update_Link" href="#" class="easyui-linkbutton update">修改</a>
                <a id="delete_Link" href="#" class="easyui-linkbutton delete">删除</a>
                <a id="resort_Link" href="#" class="easyui-linkbutton update">重新整理</a>
            </div>
        </div>
    </div>
    <div id="mainGrid"></div>
</div>
</body>
</html>